package com.aote.entity.propertygather;

import java.util.Hashtable;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;



/**
 * 属性收集工厂
 * 
 */
public class PropertyGatherFactory {

	private static PropertyGatherFactory self = new PropertyGatherFactory();

	private PropertyGatherFactory() {

	}

	public static PropertyGatherFactory getInstance() {
		return self;
	}

	public Hashtable getPropertys(Element pageElem, Hashtable attrs) {
		Hashtable result = new Hashtable();
		// 从页面总得到属性收集器配置
		NodeList list = pageElem.getElementsByTagName("propertyGather");
		for (int i = 0; i < list.getLength(); i++) {
			// 创建属性收集器
			Element elem = (Element) list.item(i);
			String className = elem.getAttribute("className");
			PropertyGather pg = this.createPropertyGather(className);
			result.putAll(pg.gather(pageElem, attrs));
		}
		return result;
	}

	/**
	 * 创建属性收集器
	 */
	private PropertyGather createPropertyGather(String className) {
		try {
			PropertyGather result = (PropertyGather) Class.forName(className)
					.newInstance();
			return result;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
